<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">


    <style>
        .xm-select {
            width: 800px; /* 设置选择框的宽度 */
            height: auto; /* 设置选择框的高度 */
        }

        .xm-select > .xm-body {
            max-height: 400px !important; /* 设置下拉列表的最大高度 */
            overflow-y: auto !important;  /* 启用垂直滚动 */
            display: flex;  /* 使用flex布局 */
            flex-wrap: wrap; /* 允许换行 */
        }

        .xm-select > .xm-body .xm-option {
            flex: 1 1 45%; /* 每个选项占据45%的宽度 */
            height: auto; /* 设置每个选项高度为自动 */
            padding: 10px; /* 添加内边距 */
            display: flex; /* 使用flex布局 */
            align-items: center; /* 垂直居中 */
        }

        .scroll-body {
            max-height: 1000px; /* 设置高度为1000px */
            overflow-y: auto; /* 启用垂直滚动 */
            display: flex; /* 使用flex布局 */
            flex-wrap: wrap; /* 允许换行 */
        }

        .scroll-body .xm-option {
            flex: 1 1 30%; /* 每个选项占据30%的宽度，三列布局 */
            box-sizing: border-box; /* 包含内边距和边框 */
            padding: 10px; /* 添加内边距 */
        }

    </style>
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>货币日志</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">渠道类型</label>
                            <div class="layui-input-inline">
                                <div id="serverGroup"></div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">选择区服:</label>
                            <div class="layui-input-inline">
                                <select name="gameArea" class="layui-select" >

                                    <option v-for="(item,index) in services" :value="item.server_id" :selected="index==0">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">玩家账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">角色名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="roleName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">角色ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="roleId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">金额</label>
                            <div class="layui-inline">
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="number" name="amountChangedBegin" setp="1" min="0" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="number" name="amountChangedEnd" step="1" min="1" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">流水号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="code" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">货币类型</label>
                            <div class="layui-input-inline">
                                <select name="moneyType">
                                    <option value="">请选择</option>
                                    <option value="10">金币</option>
                                    <option value="11">金券</option>
                                    <option value="20">银币</option>
                                    <option value="21">铜币</option>
                                    <option value="30">公会资金</option>
                                    <option value="31">公会活跃度</option>
                                    <option value="32">公会贡献</option>
                                    <option value="40">角色经验</option>
                                    <option value="41">活跃度</option>
                                    <option value="42">PK值</option>
                                    <option value="50">功勋</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline"  style="width: 600px;">
                            <label class="layui-form-label">操作类型</label>
                            <div class="layui-input-inline">
                                <div id="opTypes"></div>
                            </div>
                        </div>
                        <div class="layui-inline" style="margin-left: 300px;">
                            <label class="layui-form-label">记录时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="createDateBegin" id="createTime0"
                                       placeholder="开始时间" autocomplete="off" class="layui-input" />
                                <input type="text" name="createDateEnd" id="createTime1"
                                       placeholder="截止时间" autocomplete="off" class="layui-input" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon"></i>搜 索</button>
                        </div>

                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export" auth="moneyChange:export">导出</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="exportall" auth="moneyChange:export">全服导出()</button>

    </div>
</script>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script src="/xm-select-v1.2.4/xm-select.js"></script>
<script>
    var opTypes = getEnum('operType')
    var serverGroup = getEnum('serverGroup')

    new Vue({
        el: "#app",
        data: {
            services: JSON.parse(localStorage.getItem('services')),
        },
        mounted: function () {
            var _this = this;

            layui.use(['form', 'table','laydate'], function () {
                 $ = layui.jquery,
                    form = layui.form,
                    laydate = layui.laydate,
                    table = layui.table,
                    laydate=layui.laydate;
                laydate.render({
                    elem: '#createTime0',
                    value: getYmd(0)
                });
                laydate.render({
                    elem: '#createTime1',
                    value: getYmd(1)
                })
                var data = [];
                for(var k in opTypes){
                    var v = opTypes[k];
                    data.push({
                        name:v.name,
                        value:v.id,
                    })

                }

                xmSelect.render({
                    el: '#opTypes',
                    name:"opTypes",
                    language: 'zn',
                    filterable: true, // 启用搜索
                    toolbar: { show: true }, // 显示全选/清空工具条
                    data: data,
                    style:{width:'800px'},
                    height: '1200px',
                })

                var dataSg = [];
                for(var k in serverGroup){
                    var v = serverGroup[k];
                    dataSg.push({
                        name:v.name,
                        value:v.id,
                    })
                }

                xmSelect.render({
                    el: '#serverGroup',
                    name:"serverGroup",
                    language: 'zn',
                    data: dataSg,
                    on: function(data){
                        // 选择器值发生变化时触发
                        console.log('DATA:', data);
                        var selectedValues = data.arr.map(item => item.value);

                        // 在这里编写您想要执行的方法
                        handleServerGroupChange(selectedValues);
                    }
                })

                function handleServerGroupChange(selectedValues) {
                    // 在这里编写您想要执行的逻辑
                    if (selectedValues.length === 0) {
                        // 如果 selectedValues 为空数组,则不发送请求
                        console.log('No server groups selected.');
                        return;
                    }

                    console.log('Selected server groups:', selectedValues);
                    var url = '/admin/server/serverList';
                    var params = { groups: selectedValues };
                    var paramsString = $.param(params);
                    $.get(url + '?' + paramsString, function(res) {
                        console.log('res:', res.data);
                        _this.$set(_this, 'services', res.data);
                        _this.$nextTick(function() {
                            console.log('进来了么:');
                            form.render();
                        });
                    });
                }
                table.render({
                    width:1662,
                    elem: '#currentTableId',
                    where:form.val('table-search'),
                    url: '/admin/moneyChange/paginate',
                    defaultToolbar: ['filter', 'print'],
                    toolbar: '#toolbarDemo',
                    cols: [[
                        {type: "checkbox", width: 50},
                        {field: 'logDate', title:'记录时间',width:180 },
                        {field: 'serverId', title:'服务器ID'},
                        {field: 'memberName', title:'游戏账号' },
                        {field: 'roleId', title:'角色ID'},
                        {field: 'nick', title:'角色名'},
                        {field: 'moneyTypeName', title:'货币类型'},
                        {field: 'amountBefore', title:'变化前'},
                        {field: 'amountChanged', title:'变动数'},
                        {field: 'amountAfter', title:'变化后'},

                        {field: 'jylsh', title:'交易流水号',templet:function () {
                                return '功能待定';
                        }},
                        { field:"opTypeName",title:"操作类型",
                            templet:function (d) {
                                if (d.opTypeName) {
                                    return d.opTypeName;
                                } else {
                                    return d.opType;
                                }
                            }
                        }
                    ]],
                    limits: [10, 15, 20, 25, 50, 100],
                    limit: 15,
                    page: true,
                    skin: 'line'
                });

                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {
                    //执行搜索重载
                    table.reload('currentTableId', {
                        page: {
                            curr: 1
                        }
                        , where:form.val('table-search'),
                    }, 'data');
                    return false;
                });


                table.on('toolbar(currentTableFilter)', function (obj) {
                    if(obj.event === 'export'){ //导出
                        var searchData = form.val('table-search');
                        searchData.page = 1;
                        searchData.limit = 9999999;
                        var layerIndex = layer.msg("请求中请耐心等待...",{icon:16,time:999999999});
                        $.get('/admin/moneyChange/export',searchData,function(res){
                            layer.close(layerIndex)
                            browserDownload("/" + res.data);
                        });
                    }
                    if(obj.event === 'exportall'){ //导出
                        var searchData = form.val('table-search');
                        searchData.page = 1;
                        searchData.limit = 9999999;
                        var layerIndex = layer.msg("请求中请耐心等待...",{icon:16,time:999999999});
                        $.get('/admin/moneyChange/exportAll',searchData,function(res){
                            layer.close(layerIndex)
                            browserDownload("/" + res.data);
                        });
                    }
                });




            });
        }
    })

</script>
</body>
</html>